﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;

namespace Moni
{
    class DBHelper
    {
        public static string connstr = "server=.;database=Admin;Integrated Security=true";

        //查询
        public static SqlDataReader select(string sql) 
        {
            //创建连接对象
            SqlConnection conn = new SqlConnection(connstr);
            //创建命令对象
            SqlCommand cmd = new SqlCommand(sql,conn);
            //打开数据库
            conn.Open();

            return cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
        }

        //增删改
        public static bool Datann(string sql) 
        {
            //创建连接对象
            SqlConnection conn = new SqlConnection(connstr);
            //创建命令对象
            SqlCommand cmd = new SqlCommand(sql, conn);
            //打开数据库
            conn.Open();

            int muan = cmd.ExecuteNonQuery();
            return muan > 0;
            //关闭数据库
            conn.Close();
        }

    }

    
}
